package influence.propagation.implementation;

import influence.propagation.core.NodeModel;
import influence.propagation.core.PropertyNodeModel;

import java.util.HashMap;
import java.util.Map;

public class IndependentCascadeActiveNode implements NodeModel {
	
	private Map<String, Object> properties = new HashMap<>();

	@Override
	public Object getProperty(PropertyNodeModel pm) {
		return properties.get(pm.toString());
	}

	protected void addProperty(PropertyNodeModel key, Object value){
		properties.put(key.toString(), value);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((properties == null) ? 0 : properties.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		IndependentCascadeActiveNode other = (IndependentCascadeActiveNode) obj;
		if (properties == null) {
			if (other.properties != null)
				return false;
		} else if (!properties.equals(other.properties))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "IndipendentCascadeActiveNode [properties=" + properties + "]";
	}

	@Override
	public int compareTo(NodeModel o) {
		Long idO = o.getId();
		Long id = this.getId();
		return id.compareTo(idO);
	}

	@Override
	public Long getId() {
		return (Long) properties.get(ActiveNodeProperties.ID.toString());
	}
}
